#ifndef H_C_TIMERMGR_H
#define	H_C_TIMERMGR_H

#include "CSkipListTimerMgr.h"
#include "CWheelTimerMgr.h"

namespace TB
{
	class CTimerMgr
	{
		NON_COPYABLE(CTimerMgr)
	public:
		CTimerMgr(bool bUseSkipList = true, volatile UINT64* pqwCurTime = nullptr);

		inline void SetCurTimeOffset(UINT64 qwMilliSeconds) 
		{
			m_bUseSkipList ? m_oSkipListTimerMgr.SetCurTimeOffset(qwMilliSeconds) : m_oWheelTimerMgr.SetCurTimeOffset(qwMilliSeconds); 
		}
		inline UINT64 GetCurTime() const
		{
			return m_bUseSkipList ? m_oSkipListTimerMgr.GetCurTime() : m_oWheelTimerMgr.GetCurTime();
		}
		inline UINT32 Poll(UINT64 qwDeltaMilliSeconds)
		{
			return m_bUseSkipList ? m_oSkipListTimerMgr.Poll(qwDeltaMilliSeconds) : m_oWheelTimerMgr.Poll(qwDeltaMilliSeconds);
		}
		inline STimerUID StartTimer(UINT64 dwMilliSeconds, CONST_PTR_OR_REF(DOnTimer) ronTimer, bool bAutoFix = false)
		{
			return m_bUseSkipList ? m_oSkipListTimerMgr.StartTimer(dwMilliSeconds, ronTimer, bAutoFix) :
				m_oWheelTimerMgr.StartTimer(dwMilliSeconds, ronTimer, bAutoFix);
		}
        inline STimerUID StartTimer(UINT64 dwMilliSeconds, UINT32 dwCount, CONST_PTR_OR_REF(DOnTimer) ronTimer, bool bAutoFix = false)
		{
			return m_bUseSkipList ? m_oSkipListTimerMgr.StartTimer(dwMilliSeconds, dwCount, ronTimer, bAutoFix) :
				m_oWheelTimerMgr.StartTimer(dwMilliSeconds, dwCount, ronTimer, bAutoFix);
		}
		inline STimerUID StartTimer(UINT64 dwMilliSeconds, UINT32 dwCount, UINT64 dwFirstTimeoutMilliSeconds, CONST_PTR_OR_REF(DOnTimer) ronTimer, bool bAutoFix = false)
		{
			return m_bUseSkipList ? m_oSkipListTimerMgr.StartTimer(dwMilliSeconds, dwCount, dwFirstTimeoutMilliSeconds, ronTimer, bAutoFix) :
				m_oWheelTimerMgr.StartTimer(dwMilliSeconds, dwCount, dwFirstTimeoutMilliSeconds, ronTimer, bAutoFix);
		}
		inline BOOLN IsTimerRunning(CONST_REF(STimerUID) rsTimerUID) QCONST_FUNC
		{
			return m_bUseSkipList ? m_oSkipListTimerMgr.IsTimerRunning(rsTimerUID) : m_oWheelTimerMgr.IsTimerRunning(rsTimerUID);
		}
		inline void StopTimer(CONST_REF(STimerUID) rsTimerUID)
		{
			m_bUseSkipList ? m_oSkipListTimerMgr.StopTimer(rsTimerUID) : m_oWheelTimerMgr.StopTimer(rsTimerUID);
		}
		inline UINT64 GetNextPollTime() const
		{
			return m_bUseSkipList ? m_oSkipListTimerMgr.GetNextPollTime() : m_oWheelTimerMgr.GetNextPollTime();
		}
		inline UINT32 GetMaxCountPerPoll() const
		{
			return m_bUseSkipList ? m_oSkipListTimerMgr.GetMaxCountPerPoll() : m_oWheelTimerMgr.GetMaxCountPerPoll();
		}
		inline void SetMaxCountPerPoll(UINT32 dwMaxCountPerPoll)
		{
			m_bUseSkipList ? m_oSkipListTimerMgr.SetMaxCountPerPoll(dwMaxCountPerPoll) : m_oWheelTimerMgr.SetMaxCountPerPoll(dwMaxCountPerPoll);
		}

	private:
		CSkipListTimerMgr m_oSkipListTimerMgr;
		CWheelTimerMgr m_oWheelTimerMgr;
		bool m_bUseSkipList = true;
	};
};

#endif

